package com.ruoyi.email.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.email.vo.TmdEmailWriteAndSysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.email.mapper.TmdEmailWriteMapper;
import com.ruoyi.email.domain.TmdEmailWrite;
import com.ruoyi.email.service.ITmdEmailWriteService;
import com.ruoyi.common.core.text.Convert;


/**
 * 写信Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-04-20
 */
@Service
public class TmdEmailWriteServiceImpl implements ITmdEmailWriteService 
{
    @Autowired
    private TmdEmailWriteMapper tmdEmailWriteMapper;

    /**
     * 查询写信
     * 
     * @param id 写信主键
     * @return 写信
     */
    @Override
    public TmdEmailWrite selectTmdEmailWriteById(Long id)
    {
        return tmdEmailWriteMapper.selectTmdEmailWriteById(id);
    }

    /**
     * 查询写信列表
     * 
     * @param tmdEmailWrite 写信
     * @return 写信
     */
    @Override
    public List<TmdEmailWriteAndSysUser> selectTmdEmailWriteList(TmdEmailWrite tmdEmailWrite)
    {
        SysUser user = ShiroUtils.getSysUser();
        Long userId = user.getUserId();
        long l = userId.longValue();
        List<TmdEmailWriteAndSysUser> list =new ArrayList<>();
        List<TmdEmailWriteAndSysUser> tmdEmailWriteAndSysUsers = tmdEmailWriteMapper.selectTmdEmailWriteList(tmdEmailWrite);
        for (TmdEmailWriteAndSysUser eve:tmdEmailWriteAndSysUsers) {
            Integer receivePersonId = eve.getReceivePersonId();
            int i = receivePersonId.intValue();
            if (i==(int)l){
                list.add(eve);
            }
        }
        return list;
    }

    /**
     * 新增写信
     * 
     * @param tmdEmailWrite 写信
     * @return 结果
     */
    @Override
    public int insertTmdEmailWrite(TmdEmailWrite tmdEmailWrite)
    {

        return tmdEmailWriteMapper.insertTmdEmailWrite(tmdEmailWrite);
    }

    /**
     * 修改写信
     * 
     * @param tmdEmailWrite 写信
     * @return 结果
     */
    @Override
    public int updateTmdEmailWrite(TmdEmailWrite tmdEmailWrite)
    {
        return tmdEmailWriteMapper.updateTmdEmailWrite(tmdEmailWrite);
    }

    /**
     * 批量删除写信
     * 
     * @param ids 需要删除的写信主键
     * @return 结果
     */
    @Override
    public int deleteTmdEmailWriteByIds(String ids)
    {
        return tmdEmailWriteMapper.deleteTmdEmailWriteByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除写信信息
     * 
     * @param id 写信主键
     * @return 结果
     */
    @Override
    public int deleteTmdEmailWriteById(Long id)
    {
        return tmdEmailWriteMapper.deleteTmdEmailWriteById(id);
    }

    @Override
    public List<SysUser> selectUserName() {
        return tmdEmailWriteMapper.selectUserName();
    }
}
